<!-- 首页轮播图下方的各个分类的商品页面 -->
<template>
	<view class="">
		<u-navbar :title="name" placeholder autoBack></u-navbar>
		<template v-if="goodslist.length">
			<view class="flex justify-between bg-white " style="flex-wrap: wrap;margin:0 30rpx;">
				<block v-for="(item,index) in goodslist" :key="index">
					<commonItem :item="item"></commonItem>
				</block>
			</view>
			<view class="flex align-center justify-center my-2">
				<u-loadmore :status="status" color="#ccc" fontSize="15"></u-loadmore>
			</view>
		</template>
		<template v-else>
			<u-empty marginTop="150"></u-empty>
		</template>
		
		
	</view>
</template>

<script>
	export default{
		data(){
			return{
				name:'',
				cateId:'',
				goodslist:[],
				status: 'loadmore',
				isFinish: true,
				page:1
			}
		},
		onLoad(e) {
			this.name = e.name
			this.cateId = e.cateId
			this.getData()
		},
		onReachBottom() {
			if (!this.isFinish) {
				return;
			}
			this.page = this.page + 1
			this.status = 'loading';
			this.$api.classifiedGoods({
				page:this.page,
				cate_id:this.cateId,
			}).then(res => {
				if (res.code === 1) {
					this.goodslist = [...this.goodslist, ...res.data]
					if (res.data.length === 0) {
						this.status = 'nomore'
						this.isFinish = false
					}else{
						this.status = 'loadmore'
					}
				}
			})
		
		},
		methods:{
			getData(){
				let parmar = {
					cate_id:this.cateId,
					page:1
				}
				this.$api.classifiedGoods(parmar).then(res=>{
					if(res.code === 1){
						this.goodslist = res.data
						console.log('111',this.goodslist);
					}
				})
			}
		}
	}
</script>

<style>
</style>